﻿using MediatR;
using S.PurchaseAndSales.Api.Application.Command.SheepSaleCommand;
using S.PurchaseAndSales.Infrastructure.Interface.SalesForm;
using S.PurchaseAndSales.Domain.Model;
using AutoMapper;

namespace S.PurchaseAndSales.Api.Application.CommandHandlers.SheepSaleHandler
{
    public class AddSheepSaleHandler : IRequestHandler<AddSheepSaleCommand, bool>
    {

        private readonly ISheepSaleRepository sheepSale;

        private readonly IMapper mapper;

        //
        public AddSheepSaleHandler(ISheepSaleRepository sheepSale, IMapper mapper)
        {
            this.sheepSale = sheepSale;
            this.mapper = mapper;
        }
        /// <summary>
        /// 添加羊只销售
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<bool> Handle(AddSheepSaleCommand request, CancellationToken cancellationToken)
        {
            var list = mapper.Map<SheepSaleModel>(request);
            return await sheepSale.AddAsync(list);
        }
    }
}
